package libs.yzx.zaza.util;

import android.content.Context;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.graphics.Region;
import android.util.AttributeSet;
import android.view.View;

/**
 * Created by Administrator on 2016/10/19
 */
public class CanvasTestView extends View {
    public CanvasTestView(Context context) {
        super(context);
    }

    public CanvasTestView(Context context, AttributeSet attrs) {
        super(context, attrs);
    }

    public CanvasTestView(Context context, AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);
    }



    private Paint paint = new Paint(Paint.ANTI_ALIAS_FLAG);{
        paint.setDither(true);
    }


    //   BlurMaskFilter  :  用来模糊文字
    //   Canvas drawText 是用左下角(基线位置)来定位
    //   Canvas save restore : save方法调用后,之后的对canvas的rotate translate等操作,会在调用restore之后还原,还原到save方法之前的状态;
    //    Canvas clipRect(clipPath) : 只有在clip的范围内才能绘制(如果传入Region.Op参数,则根据参数而定, 有的只有clip范围之外才能绘制,有的之内)

    @Override
    protected void onDraw(Canvas canvas) {

        paint.setColor(Color.RED);

        canvas.save();
        paint.setColor(Color.RED);
        canvas.clipRect(100,100,300,300, Region.Op.INTERSECT);
        canvas.drawRect(100,100,300,300,paint);
        paint.setColor(Color.BLUE);
        canvas.drawCircle(100,100,100,paint);
        canvas.restore();

    }

}
